
#include "Timer.h"


struct keys key[4] = {0,0,0};
extern char view;
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)  //中断回调函数
{
    if(htim -> Instance == TIM8)
    {
         key[0].key_sta = HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0);
         key[1].key_sta = HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1);
         key[2].key_sta = HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2);
         key[3].key_sta = HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0);
        
        for(char i = 0; i < 4; i++)
        {
            switch (key[i].judge_sta)
            {
                case 0: 
                {
                  if(key[i].key_sta == 0)
                  {
                    key[i].judge_sta = 1;
                    key[i].key_time = 0;
                  }
                  else 
                  {  
                    key[i].judge_sta = 0;
                  }
                }
                break;
                case 1:
                {
                  if(key[i].key_sta == 0)
                  {
                    key[i].judge_sta = 2;
                  }
                  else 
                  {  
                    key[i].judge_sta = 0;
                  }
                }
                break;
                case 2:
                {
                  if(key[i].key_sta == 1)
                  {
                           key[i].judge_sta=0;
                        if(key[i].key_time<70)
                        {
                            key[i].single_flag=1;
                        } 
                  }
                  
                      else 
                      {
                          key[i].key_time++;
                          if(key[i].key_time>70)
                          {
                            key[i].long_flag=1;
                          }
                      }
                }
                break;                   
            }
        
        }
    }

}

uint16_t cr_val1 = 0;
uint16_t cr_val2 = 0;
uint16_t frq_one = 0;
uint16_t frq_two = 0;
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
    if(htim->Instance == TIM2)
    {
        cr_val1 = HAL_TIM_ReadCapturedValue(htim,TIM_CHANNEL_1);
        __HAL_TIM_SetCounter(htim,0);
        frq_one =(80000000/80)/cr_val1;
        HAL_TIM_IC_Start(htim,TIM_CHANNEL_1);
    }
    if(htim->Instance == TIM3)
    {
        cr_val2 = HAL_TIM_ReadCapturedValue(htim,TIM_CHANNEL_1);
        __HAL_TIM_SetCounter(htim,0);
        frq_two =(80000000/80)/cr_val2;
        HAL_TIM_IC_Start(htim,TIM_CHANNEL_1);
    }
}

